export function dataConversion(data) {
  data = data.replace(/\s/g, '').replace(
      /(.{2})/g, '$1 ');
  data = data.split(' ').reverse().join('')
  return data
}

export function handleStringBuffer(arr) {
  const str =  arr.map(item => {
      return item.toString(16).length > 1 ? item.toString(16) : '0' + item.toString(16)
  }).join('').toUpperCase()
  // console.log(str)
  return str
}

export const hexStr2Num = (str) => {
  return parseInt('0x' + str, 16)
}

export const formatNumByLen = (num, len) => {
  const min = Math.pow(10, len - 1)

  return num < min ? '0'.repeat(len - 1) + num : num.toString()
}

export const sliceStr = (str, begin, end, diff = 2) => {
  if(!end) {
    return str.slice(begin * diff)
  } else {
    return str.slice(begin * diff, end * diff)
  }
}